package com.xy.biz.mc.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.mc.domain.req.CountMessageRequest;
import com.xy.tool.util.BeanUtilsEx;
import com.xy.biz.mc.domain.bo.MessageBO;
import com.xy.biz.mc.domain.po.MessagePO;
import com.xy.biz.mc.domain.query.MessageQuery;
import com.xy.biz.mc.domain.resp.GetMessageResponse;
import com.xy.biz.mc.domain.req.SaveMessageRequest;
import com.xy.biz.mc.domain.req.ListMessageRequest;

/**
 *
 *
 * @author zsp
 * @date 2021-2-25
 */
public class MessageConverter {

	public static MessagePO toPO(MessageBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new MessagePO(), true);
	}

	public static List<MessagePO> toPO(Collection<MessageBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MessagePO(), true);
	}

	public static MessageBO fromPO(MessagePO source) {
		return BeanUtilsEx.copyProperties(source, () -> new MessageBO());
	}

	public static List<MessageBO> fromPO(Collection<MessagePO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MessageBO());
	}

	public static MessageBO toBO(SaveMessageRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new MessageBO(), true);
	}

	public static List<MessageBO> toBO(Collection<SaveMessageRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new MessageBO(), true);
	}

	public static GetMessageResponse toResponse(MessageBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new GetMessageResponse());
	}

	public static List<GetMessageResponse> toResponse(Collection<MessageBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetMessageResponse());
	}

	public static MessageQuery toQuery(ListMessageRequest source) {
		if(null == source) {
			return null;
		}
		MessageQuery target = new MessageQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

	public static MessageQuery toQuery(CountMessageRequest source) {
		if(null == source) {
			return null;
		}
		MessageQuery target = MessageQuery.max().build();
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
